/// \file		WnPacket.h
/// \brief		WIND数据包类的声明文件
/// \author		xuefeng
/// \version	1.0
/// \date		2011-07-19
/// \history	2011-07-19 新建

#pragma once
#include <boost/thread.hpp>

// socket完整数据流构成方式
// 1. 1个字节的流头校验位(STX)
// 2. 8字节包头TAG_PACKET_HEADER
// 3. 若干字节的包体
// 4. 1个字节的流尾校验位(ETX)

/// \brief WIND数据包头结构
struct TAG_PACKET_HEADER
{
	/// \brief 开始标志
	unsigned char bStartFlag;
	/// \brief 包头长度
	unsigned char bHeaderLen;
	/// \brief 检查索引
	unsigned char bCheckIndex;
	/// \brief 标志字节
	unsigned char bFlag;
	/// \brief 包体长度(字节流)
	unsigned char bPacketLen[4];
};

/// \brief WIND数据包类
class WnPacket
{
public:
	/// \brief 构造函数(供接收方使用，MDF方式)
	/// \param tHeader 包头
	/// \param pbData 包体数据指针
	/// \param unSize 包体数据大小
	WnPacket::WnPacket(const TAG_PACKET_HEADER& tHeader, const unsigned char* pbData, unsigned int unSize);

	/// \brief 构造函数(供发送方使用，MDF方式)
	/// \param pbData 包体数据指针
	/// \param unSize 包体数据大小
	/// \param bCheckIndex 检查索引
	/// \param bFlag 标志字节
	WnPacket(const unsigned char* pbData, unsigned int unSize, unsigned char bCheckIndex, unsigned char bFlag);

	/// \brief 构造函数(Other方式)
	/// \param pbData 包体数据指针
	/// \param unSize 包体数据大小
	WnPacket(const unsigned char* pbData, unsigned int unSize);

	/// \brief 析构函数
	virtual ~WnPacket(void);

	/// \brief 获取数据指针
	const unsigned char* GetPacketData() { return m_pbPacketData; }

	/// \brief 获取数据大小
	unsigned int GetPacketLength() { return m_nPacketLength; }

	/// \brief 获取包体指针
	const unsigned char* GetBodyData();

	/// \brief 获取包体大小
	unsigned int GetBodyLength();

	/// \brief 是否心跳包
	bool IsHeartBeatPacket();

private:
	// 数据指针
	unsigned char* m_pbPacketData;

	// 数据大小
	unsigned int m_nPacketLength;
};

typedef boost::shared_ptr<WnPacket> PACKET_APTR;
